import bus from '@/bus'
let data = {
  status: 'pass',
  totalItem: 1,
  pageSize: window.$pageSize,
  currentPage: 1,
  form: {
    code: '',
    title: '',
    ownerCategoryId: null,
    brandIdList: [],
    keyword: '',
    isShelf: null
  },
  columns: [{
    type: 'selection',
    width: 60,
    align: 'left',
    fixed: 'left'
  }, {
    title: '商品编码',
    key: 'code',
    align: 'left',
    minWidth: 200,
    fixed: 'left'
  }, {
    title: '商品名称',
    key: 'title',
    minWidth: 250,
    tooltip: true
  }, {
    title: '运费',
    align: 'left',
    renderHeader (h, params) {
      return <div>
        <span class='mr'>运费</span>
        <i-button size='small' onClick={() => bus.$emit('setFreightBatch')}>批量设置</i-button>
      </div>
    },
    minWidth: 150,
    render (h, params) {
      return (
        <i-select value={params.row.freightTemplateId} onOn-select={(data) => bus.$emit('changeFreight', { productId: params.row.id, freightTemplateId: data.value }) }>
          {
            params.row.freightList.map(item => {
              return <i-option value={item.id}>{ item.name }</i-option>
            })
          }
        </i-select>
      )
    }
  }, {
    title: '品牌',
    key: 'brandName',
    align: 'left',
    minWidth: 150
  }, {
    title: '分类',
    key: 'categoryName',
    align: 'left',
    minWidth: 150
  }, {
    title: 'skuId',
    key: 'skuId',
    align: 'left',
    minWidth: 200
  }, {
    title: '基础批发价',
    key: 'salePrice',
    minWidth: 150,
    align: 'left',
    render: (h, params) => {
      let disabled = params.row.productType === 'NORMAL'
      return h('div', [
        h('span', { class: 'font-red' }, '￥'),
        h('InputNumber', {
          props: {
            min: 0.01,
            max: 9999999,
            disabled: disabled,
            value: params.row.salePrice,
            precision: 2,
            step: 0
          },
          style: {
            width: '85%'
          },
          on: {
            'on-change': (value) => {
              bus.$emit('onChangeData', { val: value, params: params.row, index: params.index, type: 'salePrice' })
            },
            'on-blur': () => {
              if (params.row.salePrice != params.row.oldSalePrice) {
                bus.$emit('onBlurData', { params: params.row })
              }
            }
          }
        })
      ])
    }
  }, {
    title: '建议零售价',
    key: 'marketPrice',
    minWidth: 120,
    align: 'right',
    render: (h, params) => {
      return h('div', {
        class: 'font-red'
      }, '￥' + params.row.marketPrice)
    }
  }, {
    title: '开票价',
    key: 'invoicePrice',
    minWidth: 150,
    align: 'left',
    render: (h, params) => {
      let disabled = params.row.productType === 'NORMAL'
      return h('div', [
        h('span', { class: 'font-red' }, '￥'),
        h('InputNumber', {
          props: {
            min: 0.01,
            max: 9999999,
            disabled: disabled,
            value: params.row.invoicePrice,
            precision: 2,
            step: 0
          },
          style: {
            width: '85%'
          },
          on: {
            'on-change': (value) => {
              bus.$emit('onChangeData', { val: value, params: params.row, index: params.index, type: 'invoicePrice' })
            },
            'on-blur': () => {
              if (params.row.invoicePrice != params.row.oldInvoice) {
                bus.$emit('onBlurData', { params: params.row })
              }
            }
          }
        })
      ])
    }
  }, {
    title: '商品标签',
    key: 'tagName',
    align: 'left',
    minWidth: 320,
    render: (h, params) => {
      return h('div', {
        style: { cursor: 'pointer' },
        class: 'e1',
        attrs: {
          title: params.row.tagName
        },
        on: {
          'click': () => {
            bus.$emit('onChangeTagName', { params: params.row, index: params.index })
          }
        }
      }, params.row.tagName)
    }
  }, {
    title: '服务标签',
    key: 'productServiceTagNames',
    align: 'left',
    width: 210
  }, {
    title: '库存',
    key: 'stock',
    align: 'left',
    minWidth: 150,
    render: (h, params) => {
      let disabled = params.row.productType === 'NORMAL'
      return h('InputNumber', {
        props: {
          min: 0,
          max: 9999999,
          disabled: disabled,
          value: params.row.stock,
          precision: 0,
          step: 0
        },
        style: {
          width: '100%'
        },
        on: {
          'on-change': (value) => {
            bus.$emit('onChangeData', { val: value, params: params.row, index: params.index, type: 'stock' })
          },
          'on-blur': () => {
            if (params.row.stock != params.row.oldStock) {
              bus.$emit('onBlurData', { params: params.row })
            }
          }
        }
      })
    }
  }, {
    title: '状态',
    minWidth: 120,
    align: 'left',
    key: 'isShelf',
    filters: [{
      label: '已上架',
      value: 1
    }, {
      label: '未上架',
      value: 2
    }],
    filterMultiple: false,
    filterRemote (data, key) {
      bus.$emit('changeState', { data: data, key })
    },
    render: (h, params) => {
      let text = params.row.isShelf ? '已上架' : '未上架'
      let className = params.row.isShelf ? 'font-red' : 'font-blue'
      return h('div', {
        class: className
      }, text)
    }
  }, {
    title: '上架',
    align: 'left',
    minWidth: 80,
    render: (h, params) => {
      return h('div', [
        h('i-switch', {
          props: {
            type: 'primary',
            value: params.row.isShelf
          },
          on: {
            'on-change': (value) => {
              params.row.isShelf = value
              bus.$emit('onSwitch', params.row.id, value, params.index)
            }
          }
        })
      ])
    }
  }, {
    title: '操作',
    align: 'right',
    minWidth: 230,
    fixed: 'right',
    render: (h, params) => {
      let materielBtn = h('Button', {
        props: {
          size: 'small'
        },
        class: 'mr',
        on: {
          click: () => {
            bus.$emit('onLookMateriel', { centerProductId: params.row.centerProductId })
          }
        }
      }, '已绑物料')
      let editBtn = h('Button', {
        props: {
          size: 'small',
          type: 'primary'
        },
        class: 'mr',
        on: {
          click: () => {
            bus.$emit('onEdit', params.row.id)
          }
        }
      }, '编辑')
      let delBtn = h('Button', {
        props: {
          size: 'small',
          type: 'warning'
        },
        on: {
          click: () => {
            bus.$emit('onDelete', params.row.id, params.row.title)
          }
        }
      }, '删除')
      // let erpBtn = h('Button', {
      //   props: {
      //     size: 'small'
      //   },
      //   class: 'mr',
      //   on: {
      //     click: () => {
      //       bus.$emit('onLookErp', { centerProductId: params.row.centerProductId })
      //     }
      //   }
      // }, '查看erp关系')
      return h('div', [materielBtn, editBtn, delBtn])
    }
  }],
  data: []
}
export default data
